Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Macintosh Toolbox Essentials

Previous | Chapter Top | Chapter Contents | Next |

Sending Events

You can send events to other applications or processes using the PostHighLevelEvent function (PostHighLevelEvent) . To send Apple events to other applications, use the Apple Event Manager function AESend . The Operating System Event Manager also provides the PPostEvent (PPostEvent) and PostEvent (PostEvent) functions for posting low-level events to the Operating System event queue. The PostEvent function is used by the Toolbox Event Manager. In most cases, your application should not use the PostEvent function.

PostHighLevelEvent

You can use the PostHighLevelEvent function to send a high-level event to another application.

pascal OSErr PostHighLevelEvent (EventRecord *theEvent,
                                          unsigned long receiverID,
                                          unsigned long msgRefcon,
                                          void *msgBuff,
                                          unsigned long msgLen,
                                          unsigned long postingOptions);
theEvent
A pointer to the event record for the event to send. Your application should fill out the what , message , and where fields of the event record. Specify the kHighLevelEvent constant in the what field, the event class of the high-level event in the message field, and the event ID in the where field. You do not need to fill out the when or modifiers fields; the Event Manager automatically assigns the appropriate values to these fields when you send the message.
receiverID
The recipient of the high-level event. When sending an event to another application on the local computer, you can specify the recipient of the event by session reference number, process serial number, signature, or port name and location name. When sending an event to an application on a remote computer, you can specify the recipient only by the session reference number or by the port name and location name.
To specify a port name and location name, provide the address of a target ID structure in the receiverID parameter. To specify a process serial number, provide its address in the receiverID parameter. To specify a session reference number, or signature, provide the data in the receiverID parameter.
msgRefcon
A unique number that identifies the communication associated with this event. Your application can set this field to any value it chooses. If you are replying to a high-level event, you should use the same value in the msgRefcon parameter as specified in the high-level event that originated the request.
msgBuff
A pointer to a data buffer that contains any additional data for the event.
msgLen
The size (in bytes) of the data buffer pointed to by the msgBuff parameter.
postingOptions
Options associated with the receiverID parameter and delivery options associated with the event. You can specify one or more delivery options to indicate whether you want the other application to receive the event at the next opportunity and to indicate whether you want acknowledgment that the event was received by the other application. You use the options associated with the receiverID parameter to indicate how you are specifying the recipient of the event--whether by port name and location name in a target ID structure, by session reference number, by process serial number, or by signature.
For descriptions of the enumerators you can use to specify posting options, see "Posting Options" .

DESCRIPTION

The PostHighLevelEvent function posts the high-level event to the specified process.

If the application to which you are sending a high-level event terminates, you receive the result code sessionClosedErr the next time your application calls PostHighLevelEvent to send another high-level event to the terminated application. If you do not care about any state information about that session, you can just resend your event. Otherwise, you must restart another session and resend your event.

If your application is running in the background and posts a high-level event that requires the network authentication dialog box to be displayed, PostHighLevelEvent returns the noUserInteractionAllowed result code, does not display the network authentication dialog box, and does not send the event. If your application receives the noUserInteractionAllowed result code, you can use the Notification Manager to inform the user that your application needs attention. When the user brings your application to the foreground, you can repost the event. If the reposting is successful, your application can continue to post high-level events without further user interaction. Note that PostHighLevelEvent can return noUserInteractionAllowed only on the first posting of a high-level event to a remote target.

SPECIAL CONSIDERATIONS

The PostHighLevelEvent function may move or purge memory. You should not call this function from within an interrupt, such as in a completion routine or VBL task.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the PostHighLevelEvent function are

Trap macro

Selector

_OSDispatch

$0034

SEE ALSO

For details on how to send Apple events to other applications using the AESend function, see Inside Macintosh: Interapplication Communication .

RESULT CODES

noErr

0

No error

connectionInvalid

-609

Connection is invalid

noUserInteractionAllowed

-610

Cannot interact directly with user

sessionClosedErr

-917

Session closed

PPostEvent

In most cases, your application does not need to post events in the Operating System event queue; however, if you must do so, you can use the PPostEvent function.

pascal OSErr PPostEvent (EventKind eventCode,
                                          UInt32 eventMsg,
                                          EvQElPtr *qEl);
eventCode
A value of type EventKind (what) that indicates the type of event to post into the Operating System event queue. You specify the event kind using one or more of these values defined by the EventMask enumeration (Event Masks) : mouseDown , mouseUp , keyDown , keyUp , autoKey , and diskEvt . Do not attempt to post any other type of event in the Operating System event queue.
eventMsg
An unsigned 32-bit integer that contains the contents of the message field for the event that PPostEvent should post in the queue.
qEl
You specify the address of a pointer to an event queue entry in this parameter. PPostEvent returns the event queue entry of the posted event through this parameter.

DESCRIPTION

In the eventCode and eventMsg parameters, you specify the value for the what and message fields of the event's event record. The PPostEvent function fills out the when , where , and modifiers fields of the event record with the current time, current mouse location, and current state of the modifier keys and mouse button.

The PPostEvent function returns, through the qEl parameter, a pointer to the event queue entry of the posted event. You can change any fields of the posted event by changing the fields of its event queue entry. For example, you can change the posted event's modifier keys by changing the value of the evtQModifiers field of the event queue entry.

The PPostEvent function posts only events that are enabled by the system event mask. If the event queue is full, PPostEvent removes the oldest event in the queue and posts the new event.

Do not post any events other than mouse-down, mouse-up, key-down, key-up, auto-key, and disk-inserted events in the Operating System event queue. Attempting to post other events into the Operating System event queue interferes with the internal operation of the Event Manager.

ASSEMBLY-LANGUAGE INFORMATION

You must set up register A0 and register D0 before invoking PPostEvent . The PPostEvent function returns values in registers A0 and D0.

Registers on entry

A0

Event number (low-order word)

D0

Event message (long)

Registers on exit

A0

Pointer to an event queue entry (long)

D0

Result code (low-order word)

RESULT CODES

evtNotEnb

1

Event type not valid--event not posted

noErr

0

No error

SEE ALSO

For a description of the entries in the event queue, see "The Event Queue" .

PostEvent

The Toolbox Event Manager uses the PostEvent function to post events into the Operating System event queue. In most cases, your application should not call the PostEvent function.

pascal OSErr PostEvent (EventKind eventNum,
                                         UInt32 eventMsg);
eventNum
A value that indicates the type of event to post into the Operating System event queue. You specify the event kind using one or more of these values defined by the EventMask enumeration (Event Masks) : mouseDown , mouseUp , keyDown , keyUp , autoKey , and diskEvt . Do not attempt to post any other type of event in the Operating System event queue.
eventMsg
An unsigned integer that contains the contents of the message field for the event that PostEvent should post in the queue.

DESCRIPTION

In the eventNum and eventMsg parameters, you specify the value for the what and message fields of the event's event record. The PostEvent function fills out the when , where , and modifiers fields of the event record with the current time, current mouse location, and current state of the modifier keys and mouse button.

The PostEvent function posts only events that are enabled by the system event mask. If the event queue is full, PostEvent removes the oldest event in the queue and posts the new event.

Note that if you use PostEvent to repost an event, the PostEvent function fills out the when , where , and modifier fields of the event record, giving these fields of the reposted event different values from the values contained in the original event.

Do not post any events other than mouse-down, mouse-up, key-down, key-up, auto-key, and disk-inserted events in the Operating System event queue. Attempting to post other events into the Operating System event queue interferes with the internal operation of the Event Manager.

ASSEMBLY-LANGUAGE INFORMATION

You must set up register A0 with the event code and register D0 with the event message before invoking PostEvent . When PostEvent returns, register D0 contains the result code.

Registers on entry

A0

Event number (low-order word)

D0

Event message (long)

Registers on exit

D0

Result code (low-order word)

RESULT CODES

evtNotEnb

1

Event type not valid--event not posted

noErr

0

No error


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next